import Cookies from 'js-cookie'

const TokenKey = 'EIToken'
const orgIdKey = 'orgId'
const orgIdsKey = 'orgIds'

export function getCookieToken() {
    return Cookies.get(TokenKey)
}

export function setCookieToken(token) {
    return Cookies.set(TokenKey, token)
}

export function removeCookieToken() {
    return Cookies.remove(TokenKey)
}

export function getCookieOrgId() {
    return Cookies.get(orgIdKey)
}

export function setCookieOrgId(orgId) {
    return Cookies.set(orgIdKey, orgId)
}

export function removeCookieOrgId() {
    return Cookies.remove(orgIdKey)
}


export function getCookieOrgIds() {
    return Cookies.get(orgIdsKey)
}

export function setCookieOrgIds(orgIds) {
    return Cookies.set(orgIdsKey, orgIds)
}

export function removeCookieOrgIds() {
    return Cookies.remove(orgIdsKey)
}


export function getHeader(serviceName) {
    let ajxHeader = new Object();
    // let tmpToken = getCookieToken();//   uiewrwnfqrytu
    let muOrgId = 1;
    let apmOrgId = 1;
    let tmpToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb3VudHJ5IjoiIiwiY3JlYXRpb25UaW1lIjoxNzAzMjk0NDE5LCJleHAiOjE3MDMyOTgwMTksImZpcnN0TmFtZSI6ImFkbWluIiwiaWF0IjoxNzAzMjk0NDE5LCJpZCI6IjY2ZDFiNmYwLWJhNTUtNDlmNi04YjJjLTE5NDE5ZTRlMzIyMiIsImlzcyI6Indpc2UtcGFhcyIsImxhc3RNb2RpZmllZFRpbWUiOjE2OTUxMDAyOTUsImxhc3ROYW1lIjoiYWRtaW4iLCJyZWZyZXNoVG9rZW4iOiJjMDI1ODlmZi02MTU1LTQxYjYtYTk2Yy02NGRmNmY4OTczNDkiLCJzdGF0dXMiOiIiLCJ1c2VybmFtZSI6ImFkbWluQGFkdmFudGVjaC5jb20ifQ.RI1BWsHornBeg_zBe-byZ8CKaqgCgpRio-wl7OCFGoY'
    //ajxHeader['org-id'] = muOrgId;
    if (serviceName === 'apm') {
        //console.log("APM Service",apmOrgId);
        ajxHeader['org-id'] = apmOrgId;
    } else {
        console.log("M2I Service", muOrgId);
        ajxHeader['org-id'] = muOrgId;
    }
    if (tmpToken != null && tmpToken.length > 0) {
        return;
    } else {
        tmpToken = Cookies.get("uiewrwnfqrytu");
        ajxHeader.Authorization = tmpToken; //"Bearer " + tmpToken;
    }
    console.log('ajxHeader=>', ajxHeader)
    return ajxHeader
}
